<template>
  <el-dialog id="chooseCategoryDialog" title="发卡" v-model="openFlag" width="400px" append-to-body @close="closeDialog">
    <div class="ui_el_dialog_body">
      <el-form ref="form" :model="formData" :rules="rules" label-width="auto" class="dialog-form-two">
        <el-form-item label="资产编码">
          <el-input disabled v-model="currentRow.number" />
        </el-form-item>
        <el-form-item label="资产名称">
          <el-input disabled v-model="currentRow.name" />
        </el-form-item>
        <el-form-item label="RFID">
          <el-input v-model="currentRow.rfid" />
        </el-form-item>
      </el-form>
    </div>
    <template #footer>
      <div class="ui_el_dialog_footer">
        <el-button @click="close">取消</el-button>
        <el-button type="primary" style="color: #fff; background-color: #005bf5;" @click="subData">提交</el-button>
      </div>
    </template>

    <!-- <div v-if="currentRow" style="margin-bottom: 20px;">
        <div class="send-card-row">
          <label>编码:</label>
          <div class="content">
            {{currentRow.number}}
          </div>
        </div>

        <div class="send-card-row">
          <label>名称:</label>
          <div class="content">
            {{currentRow.name}}
          </div>
        </div>
        <div class="send-card-row">
          <label>RFID:</label>
          <div class="content">
            <el-input v-model="currentRow.rfid"></el-input>
          </div>
          <div>
            <el-button type="primary" @click="readTag">读卡</el-button>
          </div>
        </div>
      </div>

      <RfidDialog ref="rfidDialog" @sub="afterChooseTag"></RfidDialog>


      <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="subData">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
      </div> -->
  </el-dialog>
</template>

<script setup>

import api from "./api.js";
import RfidDialog from "@/components/RFID/RfidDialog.vue";

const rfidDialog = ref();

const { proxy } = getCurrentInstance();

const openFlag = ref(false);
const currentRow = reactive({});

const emit = defineEmits(['sub']);

function open(row) {
  Object.assign(currentRow, row);
  openFlag.value = true;
}

function close() {
  openFlag.value = false;
}

// 窗口关闭
function closeDialog() {

}

function readTag() {
  rfidDialog.value.open();
}

function afterChooseTag(tag) {

  currentRow.rfid = tag;
}

function subData() {

  api.updateAssetItem(currentRow).then(() => {
    proxy.$modal.msgSuccess("修改成功");
    openFlag.value = false;
    emit('sub');
  });
}

defineExpose({
  open
})


</script>

<style lang="scss">

</style>